home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / Storage.h < prev    next >
C/C++ Source or Header  |  1992-06-11  |  2KB  |  67 lines

  1. #ifndef Storage_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define Storage_First
  7.  
  8. #include "Types.h"
  9.  
  10. typedef void (*FreeHookFun)(void *, void *addr, size_t);
  11.  
  12. //---- Pools of fixed size storage allocators -----------------------
  13.  
  14. class Storage {
  15.     char dummy;
  16. public:
  17.     static void *Alloc(size_t sz);
  18.     static void *Alloc(size_t sz, const char *file, int line);
  19.     static void Free(void *vp);
  20.  
  21.     static void *ChunkAlloc(size_t sz);
  22.     static void ChunkFree(void *vp);
  23.  
  24.     static void *ObjectChunkAlloc(size_t sz);
  25.     static void ObjectChunkFree(void *vp);
  26.  
  27.     static void *ObjectAlloc(size_t sz);
  28.     static void *ObjectAlloc(size_t sz, const char *file, int line);
  29.     static void ObjectFree(void *vp);
  30.  
  31.     static void *ReAlloc(void *vp, size_t sz);
  32.  
  33.     static void Statistics();
  34.     static void SetFreeHook(FreeHookFun, void *data);
  35.     static void FreeAll();
  36.     static void EnableStatistics(int size= -1, int ix= -1);
  37. };
  38.  
  39. extern "C" void *Realloc(void*, size_t);
  40.  
  41. inline void *operator new(size_t sz, const char *file, int line)
  42.     { return Storage::Alloc(sz, file, line); }
  43.  
  44. #define dnew new(__FILE__, __LINE__)
  45.  
  46. //---- misc ---------------------------------------------------------
  47.  
  48.  
  49. #if defined(sun) || defined(sony)
  50.  
  51. #   if defined(sparc) && !defined(alloca)
  52. #       define alloca(x) __builtin_alloca(x)
  53. #   endif
  54.  
  55. #   if !defined(sony) && !defined(__GNUG__)
  56.     extern "C" void *alloca(size_t);
  57. #   endif
  58.  
  59. #   define Alloca(x) alloca(x)
  60. #   define Freea(x) 
  61. #else
  62. #   define Alloca(x) ((void*) (new char[x]))
  63. #   define Freea(x) delete (x)
  64. #endif
  65.  
  66. #endif
  67.